package com.ruoyi.project.knowledge.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.project.fusion.domain.HumanResourceScores;
import com.ruoyi.project.knowledge.domain.OverallScores;
import com.ruoyi.project.knowledge.service.DataOptimizationService;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/rest/data/management/enterprise")
public class DataOptimizationController {
    @Autowired
    private DataOptimizationService optimizationService;

    @GetMapping("/overall/scores/query")
    public List<OverallScores> getOverallScores(String chainType, String scenario, int priorityType) {
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String userName = user.getUserName();
        if(Objects.equals(userName, "admin")){
            return optimizationService.getOverallScores(chainType, scenario, priorityType);
        }
        else {
            List<OverallScores> list = new ArrayList<>();
            for (OverallScores overallScores : optimizationService.getOverallScores(chainType, scenario, priorityType)){
                if(Objects.equals(overallScores.getEnterpriseName(), userName)){
                    list.add(overallScores);
                }
            }
            return list;
        }
    }
}
